package com.woniuxy.Response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther linke
 * @create 2021-10-19 11:09
 */
@WebServlet("/responseDemo02")
public class ResponseDemo02 extends HttpServlet {
    /**
     * 重定向
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("responseDemo02...执行了");

      /*//方式一：重定向
        //设置状态码
        resp.setStatus(302);

        //设置location
        resp.setHeader("location","/web03/responseDemo01");*/

         //方式二：重定向
        resp.sendRedirect("/web03/responseDemo01");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
